package com.lincoln.entity.picture;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.lincoln.entity.base.BaseEntity;
import com.lincoln.entity.user.DbUser;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;

/**
 * 权限(最细)这里需要配合代码实现权限
 */
@Data
@Entity(name = "picture")
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})//转json忽略参数
public class DbPicture extends BaseEntity {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id",nullable = false)
    @NotFound(action = NotFoundAction.IGNORE)
    protected DbUser user;

    //显式主键,url上使用,生成规则:md5(id+width+height+createTime)
    @Column(name = "pic_id", columnDefinition = "varchar(100)", length = 200, nullable = false)
    String picId;

    //图片类型(image/jpeg)
    @Column(name = "content_type", columnDefinition = "varchar(20)", length = 20, nullable = false)
    String contentType;

    //宽度
    @Column(name = "width", columnDefinition = "int(11)", length = 11)
    Integer width;

    //高度
    @Column(name = "height", columnDefinition = "int(11)", length = 11)
    Integer height;

    //大小(单位:字节)
    @Column(name = "size", columnDefinition = "int(11)", length = 11)
    Integer size;

    //公开的(私有的访问需要本人身份,半公开需要登陆状态)
    @Column(name = "overt", nullable = false)
    Integer overt;

}
